from selenium.webdriver.common.by import By
from utils.log_utils import logger
from page_object.base_page import BasePage


class AddDepartmentPage(BasePage):
    __INPUT_DEPARTMENT_NAME = (By.CSS_SELECTOR, "[name='name']")
    __LIST_DEPARTMENT = (By.CSS_SELECTOR, ".js_toggle_party_list")
    __CHOOSE_DEPARTMENT = (By.XPATH, "//*[text()='所属部门']/..//*[text()='研发部']")
    __BTN_CONFIRM = (By.LINK_TEXT, "确定")

    def fill_and_choose_department(self, company_name):
        logger.info(f"正在填写部门信息，部门名称是：{company_name}")

        self.do_send_keys(company_name, self.__INPUT_DEPARTMENT_NAME)
        self.do_find(self.__LIST_DEPARTMENT).click()
        self.do_find(self.__CHOOSE_DEPARTMENT).click()
        self.do_find(self.__BTN_CONFIRM).click()

        from page_object.contacts_page import ContactsPage
        return ContactsPage(self.driver)
